<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item style="width: 160px">
        <el-input v-model="dataForm.activityName" placeholder="输入活动名称" clearable></el-input>
      </el-form-item>
      <el-form-item style="width: 160px;">
        <el-input v-model="dataForm.fellowName" placeholder="输入会员姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
            v-model="date"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-select clearable v-model="dataForm.categoryId" placeholder="会员类型">
          <el-option v-for="item in categoryType"
                     :key="item.key"
                     :label="item.value"
                     :value="item.key">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="openDialog">输出成excel</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%;">
      <el-table-column
          prop="name"
          header-align="center"
          align="center"
          label="活动名称">
      </el-table-column>
      <el-table-column
          prop="startTime"
          header-align="center"
          align="center"
          label="活动时间">
      </el-table-column>
      <el-table-column
          prop="duringTime"
          header-align="center"
          align="center"
          label="活动时长">
      </el-table-column>
      <el-table-column
          prop="fellowName"
          header-align="center"
          align="center"
          label="姓名">
      </el-table-column>
      <el-table-column
          prop="gender"
          header-align="center"
          align="center"
          label="性别">
        <template v-slot:default="scope">
          {{ scope.row.gender === 0 ? '男' : '女' }}
        </template>
      </el-table-column>
      <el-table-column
          prop="category"
          header-align="center"
          align="center"
          label="类型">
        <template v-slot:default="scope">
          {{ scope.row.category === 0 ? '会员' : '非会员' }}
        </template>
      </el-table-column>
      <el-table-column
          prop="age"
          header-align="center"
          align="center"
          label="年龄">
      </el-table-column>
      <el-table-column
          prop="address"
          header-align="center"
          align="center"
          label="居住地址">
      </el-table-column>
      <el-table-column
          prop="tel"
          header-align="center"
          align="center"
          label="电话">
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <file-name-input v-if="dialogVisible" ref="fileNameInput" @export="exportList"></file-name-input>
  </div>
</template>

<script>
import service from "@/utils/httpRequest";
import fileNameInput from "@/views/modules/activityRecord/fileName-input.vue";

export default {
  components: {fileNameInput},
  data() {
    return {

      dialogVisible: false,
      categoryType: [
        {
          key: 0,
          value: '会员',
        },
        {
          key: 1,
          value: '非会员'
        }
      ],
      date: [],
      dataForm: {
        activityName: '',
        fellowName: '',
        categoryId: ''
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
    }
  },
  mounted() {
    this.getDataList();
  },
  methods: {
    //打开对话框
    openDialog() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.fileNameInput.visible = true;
      })
    },
    //导出数据列表
    exportList(fileName) {
      service({
        method: 'POST',
        url: '/lovehelp/activity/exportfellowsactivity',
        params: {
          'fileName': fileName,
          'activityName': this.dataForm.activityName,
          'fellowName': this.dataForm.fellowName,
          'startTime': this.date ? this.date[0] : '',
          'endTime': this.date ? this.date[1] : '',
          'categoryId': this.dataForm.categoryId
        }
      }).then(res => {
        if (res.code === 200) {
          this.$message.success("导出成功");
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      service({
        method: 'GET',
        url: '/lovehelp/activity/fellowactivitylist',
        params: {
          'page': this.pageIndex,
          'limit': this.pageSize,
          'activityName': this.dataForm.activityName,
          'fellowName': this.dataForm.fellowName,
          'startTime': this.date ? this.date[0] : '',
          'endTime': this.date ? this.date[1] : '',
          'categoryId': this.dataForm.categoryId
        }
      }).then(res => {
       
        if (res.code === 200) {
          this.dataList = res.page.list
          this.totalPage = res.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
  }
}
</script>
